package com.my.simple.service.auth;

import com.my.simple.entity.auth.User;
import com.my.simple.entity.auth.UserRole;
import com.my.simple.repository.dao.AuthUserDao;
import com.my.simple.repository.dao.AuthUserRoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private AuthUserDao userDao;
    @Autowired
    private AuthUserRoleDao userRoleDao;
    @Autowired
    private AuthService authService;

    @Override
    public User getUserById(Integer userId) {
        return userDao.getUserById(userId);
    }

    @Override
    public List<User> getAllUser() {
        return userDao.getAllUser();
    }

    @Override
    public void addUser(User user) {
        userDao.addUser(user);
    }

    @Override
    public void deleteUserById(Integer userId) {
        userDao.deleteUserById(userId);
    }

    @Override
    public void updateUser(User userItem) {
        userDao.updateUser(userItem);
    }

    @Override
    public void addUserRole(Integer userId, Integer roleId) {
        userRoleDao.addUserRole(userId, roleId);
    }

    @Override
    public void deleteUserRole(Integer userId, Integer roleId) {
        userRoleDao.deleteUserRole(userId, roleId);
    }

    @Override
    public List<UserRole> getUserRoleByUserId(Integer userId) {
        return userRoleDao.getUserRoleByUserId(userId);
    }

    @Override
    public  void updateUserRole(List<UserRole> userRoleEntityList){
        authService.updateUserRole(userRoleEntityList);
    }

    @Override
    public User getUserByAccount(String userAccount) {
        return  userDao.getUserByAccount(userAccount);
    }
}
